/*
 * @Author: jqgao2
 * @Date: 2022-11-15 10:49:49
 * @LastEditTime: 2022-12-19 15:47:29
 * @Description: 路由文件
 * @FilePath: \h5-cli\src\router\index.ts
 * @LastEditors: jqgao2
 */
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";

const routes: Array<RouteRecordRaw> = [
  {
    path: "/h5/",
    redirect: "h5/jumpxcx",
  },
  // {
  //   path: "/h5/help",
  //   name: "help",
  //   component: () => import(/* webpackChunkName: "help" */ "@/pages/help.vue"),
  //   meta: {
  //     title: "使用帮助",
  //   },
  // },
  // {
  //   path: "/h5/helpTip/:id",
  //   name: "helpTip",
  //   component: () =>
  //     import(/* webpackChunkName: "helpTip" */ "@/pages/helpDetail.vue"),
  //   beforeEnter: (to, from, next) => {
  //     to.meta.title = to.query.qs || "使用帮助";
  //     next();
  //   },
  // },
  {
    path: "/h5/jumpxcx",
    name: "jumpxcx",
    component: () =>
      import(/* webpackChunkName: "jumpxcx" */ "@/pages/jumpXcx.vue"),
    meta: {
      title: "跳转到小程序",
    },
  },
];

const router = createRouter({
  history: createWebHistory("/"),
  routes,
});

// 设置页面title
router.afterEach((to, from) => {
  // 先判断类型再赋值
  if (typeof to.meta?.title === "string") {
    document.title = to.meta?.title;
  }
});

export default router;
